using ns0;
using ns4;
using System;
using System.Collections.Generic;
namespace ns9
{
	public abstract class UPCEANWriter : Writer
	{
		public virtual ByteMatrix encode(string contents, BarcodeFormat format, int width, int height)
		{
			return this.encode(contents, format, width, height, null);
		}
		public virtual ByteMatrix encode(string contents, BarcodeFormat format, int width, int height, Dictionary<object, object> hints)
		{
			if (contents == null || contents.get_Length() == 0)
			{
				throw new ArgumentException("Found empty contents");
			}
			if (width < 0 || height < 0)
			{
				throw new ArgumentException(string.Concat(new object[]
				{
					"Requested dimensions are too small: ",
					width,
					'x',
					height
				}));
			}
			sbyte[] sbyte_ = this.encode(contents);
			return UPCEANWriter.smethod_0(sbyte_, width, height);
		}
		private static ByteMatrix smethod_0(sbyte[] sbyte_0, int int_0, int int_1)
		{
			int num = sbyte_0.Length;
			int num2 = num + (UPCEANReader.int_4.Length << 1);
			int num3 = Math.Max(int_0, num2);
			int num4 = Math.Max(1, int_1);
			int num5 = num3 / num2;
			int num6 = (num3 - num * num5) / 2;
			ByteMatrix byteMatrix = new ByteMatrix(num3, num4);
			sbyte[][] array = byteMatrix.Array;
			sbyte[] array2 = new sbyte[num3];
			for (int i = 0; i < num6; i++)
			{
				array2[i] = (sbyte)SupportClass.Identity(255L);
			}
			int num7 = num6;
			for (int i = 0; i < num; i++)
			{
				sbyte b = (sbyte_0[i] == 1) ? 0 : ((sbyte)SupportClass.Identity(255L));
				for (int j = 0; j < num5; j++)
				{
					array2[num7 + j] = b;
				}
				num7 += num5;
			}
			num7 = num6 + num * num5;
			for (int i = num7; i < num3; i++)
			{
				array2[i] = (sbyte)SupportClass.Identity(255L);
			}
			for (int j = 0; j < num4; j++)
			{
				Array.Copy(array2, 0, array[j], 0, num3);
			}
			return byteMatrix;
		}
		protected internal static int appendPattern(sbyte[] target, int int_0, int[] pattern, int startColor)
		{
			if (startColor != 0 && startColor != 1)
			{
				throw new ArgumentException("startColor must be either 0 or 1, but got: " + startColor);
			}
			sbyte b = (sbyte)startColor;
			int num = 0;
			for (int i = 0; i < pattern.Length; i++)
			{
				for (int j = 0; j < pattern[i]; j++)
				{
					target[int_0] = b;
					int_0++;
					num++;
				}
				b ^= 1;
			}
			return num;
		}
		public abstract sbyte[] encode(string contents);
	}
}
